﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using Maticsoft.Model;
namespace Maticsoft.BLL
{
    //listfrontend
    public partial class listfrontend
    {

        private readonly Maticsoft.DAL.listfrontend dal = new Maticsoft.DAL.listfrontend();
        public listfrontend()
        { }

        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.listfrontend model)
        {
            return dal.Add(model);

        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.listfrontend model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string datetime, int number)
        {

            return dal.Delete(datetime, number);
        }
        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            return dal.DeleteList(IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.listfrontend GetModel(int ID)
        {

            return dal.GetModel(ID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Maticsoft.Model.listfrontend> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Maticsoft.Model.listfrontend> DataTableToList(DataTable dt)
        {
            List<Maticsoft.Model.listfrontend> modelList = new List<Maticsoft.Model.listfrontend>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Maticsoft.Model.listfrontend model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Maticsoft.Model.listfrontend();
                    if (dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    model.vendor = dt.Rows[n]["vendor"].ToString();
                    model.bitPart = dt.Rows[n]["bitPart"].ToString();
                    model.deviceId = dt.Rows[n]["deviceId"].ToString();
                    model.valueMapping = dt.Rows[n]["valueMapping"].ToString();
                    if (dt.Rows[n]["code"].ToString() != "")
                    {
                        model.code = int.Parse(dt.Rows[n]["code"].ToString());
                    }
                    model.message = dt.Rows[n]["message"].ToString();
                    if (dt.Rows[n]["stationNumber"].ToString() != "")
                    {
                        model.stationNumber = int.Parse(dt.Rows[n]["stationNumber"].ToString());
                    }
                    if (dt.Rows[n]["timestamp"].ToString() != "")
                    {
                        model.timestamp = long.Parse(dt.Rows[n]["timestamp"].ToString());
                    }
                    if (dt.Rows[n]["displayTime"].ToString() != "")
                    {
                        model.displayTime = DateTime.Parse(dt.Rows[n]["displayTime"].ToString());
                    }
                    if (dt.Rows[n]["electricityCosume"].ToString() != "")
                    {
                        model.electricityCosume = decimal.Parse(dt.Rows[n]["electricityCosume"].ToString());
                    }
                    if (dt.Rows[n]["accumulateVolume"].ToString() != "")
                    {
                        model.accumulateVolume = decimal.Parse(dt.Rows[n]["accumulateVolume"].ToString());
                    }
                    if (dt.Rows[n]["count"].ToString() != "")
                    {
                        model.count = int.Parse(dt.Rows[n]["count"].ToString());
                    }


                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }
        #endregion

    }
}